home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.net;
-
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.Vector;
- import symjava.lang.Bignum;
- import symjava.sql.Date;
- import symjava.sql.SQLException;
- import symjava.sql.Time;
- import symjava.sql.Timestamp;
-
- public class NetRecord extends ServerObject {
- int _length = 0;
- byte _state = 105;
- int _rowNum = 0;
- Vector _fields = new Vector();
- Vector _changedFields = new Vector();
- InputStream _stream = null;
- int _lastProj = 1;
-
- Vector getFields() {
- return this._fields;
- }
-
- public void setState(byte newState) {
- this._state = newState;
- }
-
- public byte getState() {
- return this._state;
- }
-
- public int getRecordNum() {
- return this._rowNum;
- }
-
- int getType() {
- return 59;
- }
-
- public synchronized void copy(NetRecord newrec) {
- if (this._rowNum == newrec.getRecordNum()) {
- this._state = newrec.getState();
- this._fields.removeAllElements();
- this._changedFields.removeAllElements();
- this._fields = newrec.getFields();
- }
-
- }
-
- private void checkState(boolean bforWrite) throws SQLException {
- if (this._state == 105) {
- throw new SQLException("Record is invalid.");
- } else {
- if (bforWrite) {
- if (this._state == 103) {
- throw new SQLException("Record has been marked for deletion.");
- }
-
- if (this._state == 104) {
- throw new SQLException("Record has been deleted.");
- }
- }
-
- }
- }
-
- void read(DataInputStream in) throws SQLException, IOException, ErrorException {
- this._length = in.readShort();
- byte[] leader = new byte[4];
- in.readFully(leader, 0, 4);
- this._state = in.readByte();
- this._rowNum = in.readInt();
- this._fields = new Vector();
-
- while(true) {
- ServerObject obj = (ServerObject)NetClass.getNextObject(in);
- if (obj.getType() == 50) {
- return;
- }
-
- if (obj.getBaseType() == 57) {
- this._fields.addElement(obj);
- } else {
- ((ServerObject)this).onObjectError(obj);
- }
- }
- }
-
- void write(DataOutputStream out) throws IOException {
- out.writeByte(this.getType());
- out.writeShort(9);
- out.writeBytes("ROW}");
- out.writeByte(this._state);
- out.writeInt(this._rowNum);
-
- for(int i = 0; i < this._changedFields.size(); ++i) {
- Field f = (Field)this._changedFields.elementAt(i);
- f.write(out);
- }
-
- this._changedFields.removeAllElements();
- EOT eot = new EOT();
- eot.write(out);
- }
-
- private void fieldChanged(Field f) {
- if (!this._changedFields.contains(f)) {
- this._changedFields.addElement(f);
- }
-
- if (this.getState() != 102 && this.getState() != 106) {
- this.setState((byte)101);
- } else {
- this.setState((byte)106);
- }
- }
-
- public boolean storesData(int colIndex) throws SQLException {
- return this.getField(colIndex, false).storesData();
- }
-
- public void closeStream() {
- if (this._stream != null) {
- try {
- this._stream.close();
- } catch (Exception var1) {
- }
-
- this._stream = null;
- }
-
- }
-
- private Field getField(int proj, boolean bforWrite) throws SQLException {
- this.checkState(bforWrite);
- this.closeStream();
- this._lastProj = proj;
-
- try {
- return (Field)this._fields.elementAt(proj - 1);
- } catch (ArrayIndexOutOfBoundsException var3) {
- throw new SQLException("Column index is out-of-range: " + proj);
- } catch (Exception var4) {
- throw new SQLException("Record not initialized.");
- }
- }
-
- public synchronized boolean isNull(int proj) throws SQLException {
- return this.getField(proj, false).isNull();
- }
-
- public synchronized boolean wasNull() throws SQLException {
- return this.isNull(this._lastProj);
- }
-
- public synchronized String getString(int proj) throws SQLException {
- return this.getField(proj, false).getString();
- }
-
- public synchronized boolean getBoolean(int proj) throws SQLException {
- return this.getField(proj, false).getBoolean();
- }
-
- public synchronized byte getByte(int proj) throws SQLException {
- return this.getField(proj, false).getByte();
- }
-
- public synchronized short getShort(int proj) throws SQLException {
- return this.getField(proj, false).getShort();
- }
-
- public synchronized int getInt(int proj) throws SQLException {
- return this.getField(proj, false).getInt();
- }
-
- public synchronized long getLong(int proj) throws SQLException {
- return this.getField(proj, false).getLong();
- }
-
- public synchronized float getFloat(int proj) throws SQLException {
- return this.getField(proj, false).getFloat();
- }
-
- public synchronized double getDouble(int proj) throws SQLException {
- return this.getField(proj, false).getDouble();
- }
-
- public synchronized Bignum getBignum(int proj, int scale) throws SQLException {
- return this.getField(proj, false).getBignum(scale);
- }
-
- public synchronized byte[] getBytes(int proj) throws SQLException {
- return this.getField(proj, false).getBytes();
- }
-
- public synchronized Date getDate(int proj) throws SQLException {
- return this.getField(proj, false).getDate();
- }
-
- public synchronized Time getTime(int proj) throws SQLException {
- return this.getField(proj, false).getTime();
- }
-
- public synchronized Timestamp getTimestamp(int proj) throws SQLException {
- return this.getField(proj, false).getTimestamp();
- }
-
- public synchronized InputStream getAsciiStream(int proj) throws SQLException {
- return this.getField(proj, false).getAsciiStream();
- }
-
- public synchronized InputStream getUnicodeStream(int proj) throws SQLException {
- return this.getField(proj, false).getUnicodeStream();
- }
-
- public synchronized InputStream getBinaryStream(int proj) throws SQLException {
- return this.getField(proj, false).getBinaryStream();
- }
-
- public synchronized void setNull(int proj, int sqlType) throws SQLException {
- Field f = this.getField(proj, true);
- f.setNull(sqlType);
- this.fieldChanged(f);
- }
-
- public synchronized void setBoolean(int proj, boolean x) throws SQLException {
- Field f = this.getField(proj, true);
- f.setBoolean(x);
- this.fieldChanged(f);
- }
-
- public synchronized void setByte(int proj, byte x) throws SQLException {
- Field f = this.getField(proj, true);
- f.setByte(x);
- this.fieldChanged(f);
- }
-
- public synchronized void setShort(int proj, short x) throws SQLException {
- Field f = this.getField(proj, true);
- f.setShort(x);
- this.fieldChanged(f);
- }
-
- public synchronized void setInt(int proj, int x) throws SQLException {
- Field f = this.getField(proj, true);
- f.setInt(x);
- this.fieldChanged(f);
- }
-
- public synchronized void setLong(int proj, long x) throws SQLException {
- Field f = this.getField(proj, true);
- f.setLong(x);
- this.fieldChanged(f);
- }
-
- public synchronized void setFloat(int proj, float x) throws SQLException {
- Field f = this.getField(proj, true);
- f.setFloat(x);
- this.fieldChanged(f);
- }
-
- public synchronized void setDouble(int proj, double x) throws SQLException {
- Field f = this.getField(proj, true);
- f.setDouble(x);
- this.fieldChanged(f);
- }
-
- public synchronized void setBignum(int proj, Bignum x) throws SQLException {
- Field f = this.getField(proj, true);
- f.setBignum(x);
- this.fieldChanged(f);
- }
-
- public synchronized void setString(int proj, String x) throws SQLException {
- Field f = this.getField(proj, true);
- f.setString(x);
- this.fieldChanged(f);
- }
-
- public synchronized void setBytes(int proj, byte[] x) throws SQLException {
- Field f = this.getField(proj, true);
- f.setBytes(x);
- this.fieldChanged(f);
- }
-
- public synchronized void setDate(int proj, Date x) throws SQLException {
- Field f = this.getField(proj, true);
- f.setDate(x);
- this.fieldChanged(f);
- }
-
- public synchronized void setTime(int proj, Time x) throws SQLException {
- Field f = this.getField(proj, true);
- f.setTime(x);
- this.fieldChanged(f);
- }
-
- public synchronized void setTimestamp(int proj, Timestamp x) throws SQLException {
- Field f = this.getField(proj, true);
- f.setTimestamp(x);
- this.fieldChanged(f);
- }
-
- public synchronized void setAsciiStream(int proj, InputStream x, int length) throws SQLException {
- Field f = this.getField(proj, true);
- f.setAsciiStream(x, length);
- this.fieldChanged(f);
- }
-
- public synchronized void setUnicodeStream(int proj, InputStream x, int length) throws SQLException {
- Field f = this.getField(proj, true);
- f.setUnicodeStream(x, length);
- this.fieldChanged(f);
- }
-
- public synchronized void setBinaryStream(int proj, InputStream x, int length) throws SQLException {
- Field f = this.getField(proj, true);
- f.setBinaryStream(x, length);
- this.fieldChanged(f);
- }
-
- public synchronized int getSQLType(int proj) throws SQLException {
- Field f = this.getField(proj, false);
- return f.getSQLType();
- }
-
- public synchronized Object getObject(int proj) throws SQLException {
- Field f = this.getField(proj, false);
- return f.getObject();
- }
-
- synchronized void setObject(int proj, Object obj) throws SQLException {
- Field f = this.getField(proj, true);
- f.setObject(obj);
- this.fieldChanged(f);
- }
- }
-